//
//  QHRelaxVC.swift
//  QingHuWord
//
//  Created by 李东 on 2024/3/30.
//

import UIKit
import SnapKit

class QHRelaxVC: QHBaseVC {
    
    @IBOutlet weak var fishView_top: NSLayoutConstraint!
    
    @IBOutlet weak var fishView: UIView!
    
    @IBOutlet weak var fishImgView1: UIImageView!
    @IBOutlet weak var fishImgView2: UIImageView!
    @IBOutlet weak var fishImgView3: UIImageView!
    @IBOutlet weak var fishImgView4: UIImageView!
    @IBOutlet weak var fishImgView5: UIImageView!
    @IBOutlet weak var fishImgView6: UIImageView!
    @IBOutlet weak var fishImgView7: UIImageView!
    @IBOutlet weak var fishImgView8: UIImageView!
    @IBOutlet weak var contentLabel: UILabel!
    @IBOutlet weak var desLabel: UILabel!
    @IBOutlet weak var againBtn: UIButton!
    @IBOutlet weak var finishBtn: UIButton!
    @IBOutlet weak var continueBtn: UIButton!
    var explainBtn: UIButton!
    
    var tapCount = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()

        hideNavgaitionBar()
        showBgImgView = true
        showPopBtn = true
        navTitle = "解压咸鱼"
        fishView_top.constant = CGFloat.navHeight + 25
        fishImgView1.tag = 11
        fishImgView2.tag = 12
        fishImgView3.tag = 13
        fishImgView4.tag = 14
        fishImgView5.tag = 15
        fishImgView6.tag = 16
        fishImgView7.tag = 17
        fishImgView8.tag = 18
        
        explainBtn = UIButton()
        explainBtn.setImage(UIImage(named: "icon_explain"), for: .normal)
        explainBtn.addTarget(self, action: #selector(explainHandle), for: .touchUpInside)
        view.addSubview(explainBtn)
        explainBtn.snp.makeConstraints { make in
            make.centerY.equalTo(popBtn)
            make.right.equalTo(-10)
        }
        
        fishView.isUserInteractionEnabled = true
        fishView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(fishTapClick)))
        
    }


    @objc func explainHandle() {
        navigationController?.pushViewController(QHExplainVC(), animated: true)
    }
    
    @objc func fishTapClick() {
        tapCount += 1
        if tapCount % 45 == 0 {
            let a =  10 + tapCount / 45
             for i in 11...a {
                 if let tempView = view.viewWithTag(i) {
                     tempView.isHidden = false
                 }
             }
            if tapCount == 45*8 {
                contentLabel.text = "恭喜你，“翻身”成功！"
                desLabel.text = ""
                againBtn.isHidden = false
                finishBtn.isHidden = true
                continueBtn.isHidden = true
            }else {
                contentLabel.text = "恭喜你获得一片鱼鳞"
                desLabel.text = "离咸鱼翻身更进一步啦~"
                finishBtn.isHidden = false
                continueBtn.isHidden = false
                againBtn.isHidden = true
            }
        }
    }
 
    @IBAction func againHandle(_ sender: Any) {
        tapCount = 0
        for i in 11...18 {
            if let tempView = view.viewWithTag(i) {
                tempView.isHidden = true
            }
        }
        contentLabel.text = ""
        desLabel.text = ""
        againBtn.isHidden = true
        finishBtn.isHidden = true
        continueBtn.isHidden = true
    }
    
    @IBAction func finishHandle(_ sender: Any) {
        navigationController?.popViewController(animated: true)
    }
    
    @IBAction func continueHandle(_ sender: Any) {
        contentLabel.text = ""
        desLabel.text = ""
        againBtn.isHidden = true
        finishBtn.isHidden = true
        continueBtn.isHidden = true
    }
    
}
